﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CHPM.PL.DesktopUI.Code.Validation;
using CHPM.PL.DesktopUI.Interfaces;
using CHPM.PL.DesktopUI.Presenters;
using CHPM.PL.DesktopUI.Code.Common;
using CHPM.IC.ServiceLocator;

namespace CHPM.PL.DesktopUI.UserControls
{
    public partial class NewPatientControl : UserControl, INewPatient
    {
        public NewPatientControl(IServiceLocator serviceLocator)
        {
            InitializeComponent();
        }

        public string FullName { get; set; }
        public string Card { get; set; }
        public DateTime Birthday { get; set; }
        public bool Sex { get; set; }
        public string Address { get; set; }
        public bool Chornobyl { get; set; }
        public bool Citizen { get; set; }
        public bool Sanatoriy { get; set; }
        public DateTime EnterDate { get; set; }
        public int Invalid { get; set; }
        public int TreatmentCourse { get; set; }
        public bool Ambulatory { get; set; }
        public string Phone { get; set; }
        
        #region Helpers
        public void SetAdressMessages(List<string> messages)
        {
            throw new NotImplementedException();
        }

        public void SetFullNameMessages(List<string> messages)
        {
            throw new NotImplementedException();
        }
        #endregion

        public List<string> ValidationMessages { get; set; }

        private void btnSave_Click(object sender, EventArgs e)
        {
            FullName = tbFullname.Text;
            Card = tbCard.Text;
            Address = tbAddress.Text;
            Phone = tbPhone.Text;
            Birthday = dtpBirthday.Value;
            EnterDate = dtpEnterDate.Value;
            Invalid = cbInvalid.SelectedIndex;
            TreatmentCourse = cbTreatmentCourse.SelectedIndex;
            Ambulatory = cbAmbulatory.SelectedIndex == 0;
            Sex = rbMale.Checked;
            Chornobyl = cbChornobyl.Checked;
            Citizen = cbCitizen.Checked;
            Sanatoriy = cbSanatoriy.Checked;

            //tbAddress.Validating += NewPatientValidator.AdressValidation;  

            OnUserSaving(this, null);
        }

   //     private List<Control> m_lstControlsToValidate;
       // private void SetupControlsToValidate()
       // {
       //     m_lstControlsToValidate = new List<Control>();

       //     //Add data entry controls to be validated

       //     m_lstControlsToValidate.Add(sometextbox);
       //     m_lstControlsToValidate.Add(sometextbox2);

       // }
       //private void ValidateSomeTextBox()
       //{
       //     //Call this method in validating event.
       //     //Validate and set error using error provider
       //}

       //Private void Save()
       //{
       //     foreach(Control thisControl in m_lstControlsToValidate)
       //     {
       //         if(!string.IsNullOrEmpty(ErrorProvider.GetError(thisControl)))
       //         {                    
       //             //Do not save, show messagebox.
       //             return;
       //         }
       //     }
       //  //Continue save
       //}

        public event EventHandler<ConsoleCancelEventArgs> OnUserSaving;

        public Control AsControl
        {
            get { return this; }
        }


        public FormPresenter formPresenter
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
